<?php

namespace App\Console\Commands;

use App\Models\Admin\AdminUser;
use App\Models\Admin\Goods;
use App\Models\Admin\GoodsStore;
use App\Models\Api\Store;
use Illuminate\Console\Command;

class StoreTime extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'store_time';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'store_time';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     * @return mixed
     * 30 1 * * *  php artisan store_time
     */
    public function handle()
    {
        $noeTime = time();
        $storeList = Store::select(['id', 'store_name', 'agent_end_time'])->where('status', 3)->get()->toArray();
        saveLog("商户状态定时任务执行开始===>>>",'store');
        $num = 0;
        foreach ($storeList as $item) {
            if ($item['agent_end_time'] < $noeTime) {
                $num++;
//                echo  $item['agent_end_time'];
                Store::where(['id' => $item['id']])->update(['status' => 5]);
            }
        }
        saveLog("商户状态定时任务执行-{$num}-结束===^^^",'store');
    }
}
